//#include "stdafx.h"
#include "CameraHelper.h"

CameraHelper::CameraHelper()
{
	eye = new Camera();
	cam = new Entity(EC_PIVOT);
	eye->BindEntity(cam);

	mousesent = 0.5f;

	KeyForward = 'W';
	KeyBackward = 'S';
	KeyLeft = 'A';
	KeyRight = 'D';

	AltKeyForward = VK_UP;
	AltKeyBackward = VK_DOWN;
	AltKeyLeft = VK_LEFT;
	AltKeyRight = VK_RIGHT;

	dx=0;dy=0;dz=0;
	dax=0;day=0;daz=0;

	smooth = 0.75f;

	mox = (float)MouseX();
	moy = (float)MouseY();

	speed = 1.0f;
}

CameraHelper::~CameraHelper()
{
	delete eye;
	delete cam;
}

void CameraHelper::Update()
{
	float ox = cam->X();
	float oy = cam->Y();
	float oz = cam->Z();

	float osf=0;
	float oss=0;

	if(KeyDown(KeyForward)||KeyDown(AltKeyForward))osf+=speed;
	if(KeyDown(KeyBackward)||KeyDown(AltKeyBackward))osf-=speed;
	if(KeyDown(KeyLeft)||KeyDown(AltKeyLeft))oss-=speed;
	if(KeyDown(KeyRight)||KeyDown(AltKeyRight))oss+=speed;

	cam->Move(oss,0,osf);

	dx+= (cam->X() - ox);
	dy+= (cam->Y() - oy);
	dz+= (cam->Z() - oz);

	dx*=smooth;
	dy*=smooth;
	dz*=smooth;

	cam->Translate(dx*speed,dy*speed,dz*speed);

	dax += (moy - MouseY());
	day += (mox - MouseX());

	dax*=mousesent;
	day*=mousesent;

	cam->Turn(dax,day,0);

	mox = (float)MouseX();
	moy = (float)MouseY();
}

void CameraHelper::SetMouseSentensenty(float s)
{
	mousesent = s;
}

void CameraHelper::SetMoveSmooth(float s)
{
	smooth = s;
}

void CameraHelper::SetMoveSpeed(float s)
{
	speed = s;
}

void CameraHelper::SetKeys(int up,int down,int left,int right)
{
	KeyForward = up;
	KeyBackward = down;
	KeyLeft = left;
	KeyRight = right;
}

void CameraHelper::SetAltKeys(int up,int down,int left,int right)
{
	AltKeyForward = up;
	AltKeyBackward = down;
	AltKeyLeft = left;
	AltKeyRight = right;
}

Camera* CameraHelper::GetEye()
{
	return eye;
}

Entity* CameraHelper::GetCam()
{
	return cam;
}